package org.example.campsys.mapper;

import org.apache.ibatis.annotations.*;
import org.example.campsys.model.*;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Mapper
public interface RootMapper {

    @Select("select t_sys_user.id, t_sys_user.login_name, t_sys_user.gender, t_sys_user.birthday, t_sys_user.phone, t_sys_user.email, t_sys_user.status, t_sys_user_role.role_id, " +
            "t_sys_user_role.role_id from t_sys_user join t_sys_user_role on t_sys_user.id = t_sys_user_role.user_id ")
    List<UserInfo> selUser();

    @Insert("insert into t_sys_user_role (user_id, role_id) values (#{userId}, 3)")
    Integer addManager(Integer userId);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into t_sys_user ( login_name, password, gender, birthday, phone, email, status) " +
            "values (#{loginName}, #{password}, #{gender}, #{birthday}, #{phone}, #{email}, 1)")
    Integer addUser(UserInfo userInfo);

    @Insert("insert into t_sys_user_role (user_id, role_id) values (#{id}, #{roleId})")
    Integer addRole(@Param("id") Integer id,@Param("roleId") Integer roleId);

    @Update("update t_manager_activity set category = #{category} where id = #{id}")
    Integer mngCategory(ActivityInfo activityInfo);

    @Update("update t_manager_class set class_desc = #{classDesc} where id = #{id}")
    Integer mngClass(ClassInfo classInfo);

    @Update("<script>" +
            "update t_sys_user <set>" +
            "<if test = ' loginName != null'> login_name = #{loginName}, </if>" +
            "<if test = ' password != null'> password = #{password}, </if>" +
            "<if test = ' gender != null'> gender = #{gender}, </if>" +
            "<if test = ' birthday != null'> birthday = #{birthday}, </if>" +
            "<if test = ' phone != null'> phone = #{phone}, </if>" +
            "<if test = ' email != null'> email = #{email}, </if>" +
            "<if test = ' status != null'> status = #{status} </if>" +
            "</set>" +
            "where id = #{id}" +
            "</script>")
    Integer updUser(UserInfo userInfo);
}
